﻿using System;
using System.Reflection;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using ZhukBlogLinqExamples.FieldTypes.CustomUser.Controls;

namespace ZhukBlogLinqExamples.FieldTypes.CustomUser
{
    public class CustomUserField : SPFieldUser
    {
        public CustomUserField(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        {
            Init();
        }

        public CustomUserField(SPFieldCollection fields, string typeName, string displayName)
            : base(fields, typeName, displayName)
        {
            Init();
        }

        private void Init()
        {
            Type = SPFieldType.User;
            TypeAsString = "CustomUserField";
        }

        public override BaseFieldControl FieldRenderingControl
        {
            get
            {
                BaseFieldControl control;
                if (CountRelated)
                {
                    control = new ComputedField();
                }
                else if (AllowMultipleValues)
                {
                    control = new CustomUserFieldControlMulti();
                }
                else
                {
                    control = new CustomUserFieldControl();
                }
                control.FieldName = InternalName;
                return control;
            }
        }
    }
}
